<?php
namespace app\stores\model\withdraw;
use app\common\model\CommonModel;
use think\facade\Db;

class MemberWithdrawAccountModel extends CommonModel{

    protected  $name = 'member_withdraw_account';

    protected  $pk   = 'withdraw_account_id';

    public static function onBeforeInsert($model)
    {
        $model->set("add_time", date('Y-m-d H:i:s'));
        $model->set("add_ip", request()->ip());
    }
    public static function info($where){
        $info= self::where($where)->find();
        return $info;
    }

    public static function list($where,$order,$field='*',$page=1,$limit=10){
        $query = Db::name('member_withdraw_account')
            ->when(isset($where['member_id']),function ($query) use ($where){
                $query->where(['member_id'=>$where['member_id']]);
            })
            ->when(isset($where['is_delete']),function ($query) use ($where){
                $query->where(['is_delete'=>$where['is_delete']]);
            })
            ->field($field);
        $count=$query->count();
        $list=$query->order($order)
            ->limit($limit)->page($page)
            ->select()
            ->toArray();
        return compact('count','list');
    }
    public static function up($data,$where){
        $data['edit_time']=date('Y-m-d H:i:s');
        $res=self::update($data,$where);
        return $res;
    }
}
